package com.blog4j.system.api;

import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.enums.OperationTypeEnum;
import com.blog4j.common.model.Result;
import com.blog4j.requestRate.annotation.RequestRate;
import com.blog4j.system.entity.BarrageEntity;
import com.blog4j.system.service.BarrageService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/8/18 10:51
 **/
@RestController
@RequestMapping("/api/barrage")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApiBarrageController {
    private final BarrageService barrageService;

    /**
     * 获取网站弹幕留言列表
     *
     * @return 网站弹幕留言列表
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.SYSTEM, description = "获取网站弹幕留言列表")
    @GetMapping("/list")
    public Result list() {
        return Result.ok(barrageService.list());
    }

    /**
     * 弹幕留言
     *
     * @param barrage 留言信息
     * @return 成功
     */
    @RequestRate(count = 5)
    @OperationLog(operationType= OperationTypeEnum.INSERT,
            module= ModuleTypeEnum.SYSTEM,
            description = "弹幕留言")
    @PostMapping("/addBarrage")
    public Result addBarrage(@RequestBody BarrageEntity barrage) {
        BarrageEntity barrageEntity = barrageService.addBarrage(barrage);
        return Result.ok(barrageEntity);
    }
}
